package cc.wanforme.st.server.vo;

import cc.wanforme.st.server.base.constant.ResCode;

/**
 * @author wanne
 * 2020年9月21日
 */
public class ResMessage<T> {
	// 返回码
	private String code;
	// 错误信息
	private String info;
	// 成功数据
	private T data;

	public ResMessage() {}
	
	public ResMessage(String code, String info, T data) {
		super();
		this.code = code;
		this.info = info;
		this.data = data;
	}

	public String getCode() {
		return code;
	}

	public void setCode(String code) {
		this.code = code;
	}

	public String getinfo() {
		return info;
	}

	public void setinfo(String info) {
		this.info = info;
	}

	public T getData() {
		return data;
	}

	public void setData(T data) {
		this.data = data;
	}
	
	
	// 构造者模式改进
	public static <T> ResMessage<T> newMessage(ResCode code, String messasge, T data) {
		return new ResMessage<T>(code.getCode(), messasge, data);
	}
	public static <T> ResMessage<T> success(String message,T data) {
		return new ResMessage<T>(ResCode.SUCCESS.getCode(), message, data);
	}
	public static <T> ResMessage<Void> success() {
		return new ResMessage<Void>(ResCode.SUCCESS.getCode(), ResCode.SUCCESS.getDescription(), null);
	}
	public static <T> ResMessage<T> success(T data) {
		return new ResMessage<T>(ResCode.SUCCESS.getCode(), ResCode.SUCCESS.getDescription(), data);
	}
	public static <T> ResMessage<T> fail( String messasge) {
		return new ResMessage<T>(ResCode.FAIL.getCode(), messasge, null);
	}
	public static <T> ResMessage<T> fail( String messasge, T data) {
		return new ResMessage<T>(ResCode.FAIL.getCode(), messasge, data);
	}
	
}
